package com.ymatou.iapi.im.testcase;

import com.ymatou.iapi.im.parameter.SendMessageBean;
import com.ymatou.iapi.im.parameter.SwitchSessionBean;
import com.ymatou.iapi.im.service.SwitchSessionCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymttest.business.service.ImCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.YmtMessage;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.util.List;
import java.util.Map;

/**
*切换洋管家会话
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SwitchSession{
	private static SwitchSessionBean switchsessionBean;
	private static SwitchSessionCall switchsessionCall;
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("切换洋管家会话");
	}

	@Before
	public void caseUp() {
		switchsessionBean=new SwitchSessionBean();
		switchsessionCall=new SwitchSessionCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(switchsessionCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SwitchSession_01() {
		Logger.start(true,"切换洋管家会话");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			SendMessageBean sendMessageBean = ImCallService.initSendMessage(csId,userId,"nihao");
			String messageId = ImCallService.SendMessage(sendMessageBean).get("messageId").getAsString();
			ImDefaultWapper im = new ImDefaultWapper();
			YmtMessage ymtMessage = im.selectImInfo(messageId).get(0);

			switchsessionBean.setFromUserId(csId);
			switchsessionBean.setToUserId(userId);
			switchsessionBean.setOldSessionNumber(ymtMessage.getSessionNumber());
			String newSessionNumber = TestDataManager.getRandomNum(6);
			switchsessionBean.setNewSessionNumber(newSessionNumber);
			Integer newCsid = Integer.parseInt(TestDataManager.getRandomNum(6));
			switchsessionBean.setNewCsId(newCsid);
			String newCsName = "niuniu";
			switchsessionBean.setNewCsName(newCsName);
			switchsessionCall.setData(switchsessionBean);
			switchsessionCall.callService();
			Logger.verifyEquals("Success",switchsessionCall.getString("Status"),"验证Status");
			YmtMessage ymtMessage1 = im.selectImInfo(messageId).get(0);
			Logger.verifyEquals(newSessionNumber,ymtMessage1.getSessionNumber(),"验证sessionnumber");
			Logger.verifyEquals(newCsid,ymtMessage1.getCsId(),"验证CSid");
			Logger.verifyEquals(newCsName,ymtMessage1.getCsName(),"验证CsName");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}